Skip to content

Uncaught (in promise) TypeError: Cannot read property 'register' of undefined(…) #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wklm opened this issue Apr 11, 2016 · 4 comments

Comments

@wklm
Copy link

wklm commented Apr 11, 2016

Hi,

I've got a problem with requesting a periodic sync. Error message is:

Uncaught (in promise) TypeError: Cannot read property 'register' of undefined(…)

and my registration object looks like this:

ServiceWorkerRegistration {installing: null, waiting: null, active: ServiceWorker, scope: "http://localhost:3000/", onupdatefound: null…}

So it has no requested field "periodicSync"

this is my code:

if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw', { scope: '/' }); navigator.serviceWorker.ready.then(function(registration) { console.log(registration) registration.periodicSync.register({ tag: 'get-latest-news', // default: '' minPeriod: 1000, // default: 0 powerState: 'avoid-draining', // default: 'auto' networkState: 'avoid-cellular' // default: 'online' }).then(function(periodicSyncReg) { console.log("success"); }, function() { console.log("failure"); }) }); }

What am I doing wrong?

@jkarlin
Copy link
Collaborator

jkarlin commented Apr 11, 2016

I don't believe that periodic sync is implemented in any browser. Chrome has implemented one-shot sync, as defined in https://wicg.github.io/BackgroundSync/spec/. I believe that Mozilla is implementing one-shot as well.

@wklm
Copy link
Author

wklm commented Apr 11, 2016

@jkarlin background sync is marked as enabled in chrome 49 (https://www.chromestatus.com/feature/6170807885627392) Could you please suggest me how can I implement it in my app? Are there any good tutorials around?

@jkarlin
Copy link
Collaborator

jkarlin commented Apr 11, 2016

What's implemented is the background sync specification, which currently only includes one-shot syncs.

The closest thing to a tutorial that I'm aware of is @jakearchibald 's article. There is also a demo.

@wklm
Copy link
Author

wklm commented Apr 11, 2016

@jkarlin thank you 👍

@wklm wklm closed this as completed Apr 11, 2016
@wklm wklm reopened this Apr 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants